package com.example.shushiyunsst.fragment.main.home.recycler.provider.advise_provider;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.example.library_common.adapter.multi.AdapterViewItemViewClick;
import com.example.library_common.adapter.multi.JssMultiItemViewHolder;
import com.example.library_common.adapter.multi.JssNewMultipleAdapter;
import com.example.library_common.utils.QMUIDisplayHelper;
import com.example.shushiyunsst.R;
import com.example.shushiyunsst.fragment.main.home.recycler.bean.advise_bean.AdviseH5Entity;
import com.example.shushiyunsst.fragment.main.home.recycler.bean.advise_bean.AdviseImgEntity;
import com.example.wallet.global.AppGlobals;

public class AdviseH5Provider extends JssMultiItemViewHolder<AdviseH5Entity> {

    private final int height;

    public AdviseH5Provider(View view) {
        super(view);
        int screenWidth = QMUIDisplayHelper.getScreenWidth(AppGlobals.getApplication());
        height = screenWidth / 4;
    }

    @Override
    public int getItemLayout() {
        return R.layout.advise_h5_provider_layout;
    }

    @Override
    public void convert(Context context, AdviseH5Entity mEntity) {
        super.convert(context, mEntity);
        View view = findView(R.id.frame);
        if (view !=null){
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            if (lp != null && lp.height != height) {
                lp.height = height;
                view.setLayoutParams(lp);
            }
        }
        setImageNetUrl(R.id.img,mEntity.getModUrl(),R.drawable.img_erros_bg_rect)
         .setViewClick(R.id.frame, v -> {
             if (adapter instanceof JssNewMultipleAdapter) {
                 AdapterViewItemViewClick itemViewClick =
                         ((JssNewMultipleAdapter) adapter).getAdapterViewItemViewClick();
                 if (itemViewClick != null) {
                     itemViewClick.onAdapterViewListItemViewClick(mEntity,mEntity.getItemType());
                 }
             }
         });
    }
}
